package com.hsy.crm.web.web.stone;

import com.hsy.crm.web.domain.cm.App;
import com.hsy.crm.web.domain.cm.Response;
import com.hsy.crm.web.domain.entity.StoneOther;
import com.hsy.crm.web.domain.ex.ServiceException;
import com.hsy.crm.web.domain.vo.stoneOther.StoneOtherPageVo;
import com.hsy.crm.web.domain.vo.stoneOther.StoneOtherVo;
import com.hsy.crm.web.service.impl.StoneOtherService;
import com.hsy.crm.web.web.BaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stoneOther")
public class StoneOtherAction extends BaseAction {

    @Autowired
    StoneOtherService stoneOtherService;

    @RequestMapping("/insert")
    public String insert(StoneOtherVo stoneOtherVo) {
        checkOther(stoneOtherVo.getStoneOther());
        return Response.body(stoneOtherService.insertStoneOther(stoneOtherVo));
    }

    @RequestMapping("/update")
    public String update(StoneOtherVo stoneOtherVo) {
        checkOther(stoneOtherVo.getStoneOther());
        return Response.body(stoneOtherService.updateStoneOther(stoneOtherVo));
    }

    @RequestMapping("/delete")
    public String delete(StoneOther stoneOther) {
        //checkOther(stoneOther);
        return Response.body(stoneOtherService.deleteStoneOther(stoneOther));
    }

    @RequestMapping("/page")
    public String page(StoneOtherPageVo stoneOtherPageVo) {
        checkOtherType(stoneOtherPageVo.getOtherType());
        return Response.body(stoneOtherService.page(stoneOtherPageVo));
    }

    /*@RequestMapping("/examine")
    public String examine(StoneOther stoneOther) {
        return Response.body(stoneOtherService.examine(stoneOther));
    }*/

    @RequestMapping("/invalid")
    public String invalid(StoneOther stoneOther) {
        return Response.body(stoneOtherService.invalid(stoneOther));
    }

    @RequestMapping("/getOrder")
    public String getOrder(StoneOther stoneOther) {
        checkOther(stoneOther);
        return Response.body(stoneOtherService.getOrder(stoneOther));
    }

    private static void checkOtherType(Integer otherType){
        if( otherType != App.OtherType.IN && otherType != App.OtherType.OUT ){
            throw new ServiceException("other type error");
        }
    }

    private static void checkOther(StoneOther other){
        checkOtherType(other.getOtherType());
    }

}
